<template>
  <div class="box">
    <div class="descriptions">
      <div class="user-title-box">优惠审批信息</div>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="优惠类型">
          {{ dataObj.type == 1 ? '对客报价优惠' : '结算优惠' }}
        </el-descriptions-item>
        <el-descriptions-item label="预算报价金额">{{
          dataObj.budget_quotation_amount
            ? dataObj.budget_quotation_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="预计签约金额">{{
          dataObj.expected_signing_amount
            ? dataObj.expected_signing_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="优惠金额">{{
          dataObj.discount_amount
            ? dataObj.discount_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="优惠后利润金额">{{
          dataObj.remaining_profit_amount
            ? dataObj.remaining_profit_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="优惠后成本利润率">{{
          dataObj.remaining_cost_profit_ratio
            ? dataObj.remaining_cost_profit_ratio + "%"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="优惠前利润金额">{{
          dataObj.profit_amount
            ? dataObj.profit_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="优惠前成本利润率">{{
          dataObj.cost_profit_ratio
            ? dataObj.cost_profit_ratio + "%"
            : "--"
        }}</el-descriptions-item>
      </el-descriptions>
    </div>
    <div class="descriptions">
      <div class="user-title-box">审核操作</div>
      <el-form :model="shForm" ref="shForm" label-position="top">
        <el-form-item label="" prop="reviewPassed">
          <el-radio-group v-model="shForm.reviewPassed" size="small">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="shForm.reviewPassed == 2" :label="shForm.reviewPassed == 1 ? '备注' : '理由'" prop="remark">
          <el-input :rows="4" class="input-box" v-model="shForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="shbjdSubmit('shForm')" :disabled="diaLoading"
          :loading="diaLoading">提交</el-button>
        <el-button @click="shbjdCancel('shForm')">关闭</el-button>
      </span>
    </div>
  </div>
</template>
<script>
import discountApi from '@/api/discountApi';


export default {
  name: "fsbjyhCom",
  data() {
    return {
      shForm: {
        remark: "",
        quotation_id: "",
        reviewPassed: 1,
      },
      diaLoading: false,
      dataObj: ''
    };
  },

  computed: {},
  mounted() {
    this.discountApprovalDetails();
  },
  methods: {
    // 拒绝审核
    discountReviewRejected(obj) {
      this.diaLoading = true;
      discountApi.discountReviewRejected(obj).then(res => {
        console.log(res, "拒绝审核")
        this.diaLoading = false;
        if (res.code == 200) {
          this.shbjdCancel();
        }
        this.$message({
          type: res.code == 200 ? 'success' : 'warning',
          message: res.message
        })
      })
    },
    // 通过审核
    discountReviewPassed(obj) {
      this.diaLoading = true;
      discountApi.discountReviewPassed(obj).then(res => {
        console.log(res, "审核通过")
        this.diaLoading = false;
        if (res.code == 200) {
          this.shbjdCancel();
        }
        this.$message({
          type: res.code == 200 ? 'success' : 'warning',
          message: res.message
        })
      })
    },
    // 优惠单详情
    discountApprovalDetails() {
      if (!this.$route.query.id) return;
      discountApi.discountApprovalDetails({
        discount_id: this.$route.query.id
      }).then(res => {
        console.log(res, "优惠单审核")
        if (res.code == 200) {
          this.dataObj = res.data;
        }
      })
    },
    // 审核
    shbjdCancel(formName) {
      this.$goBackTab(this);
    },
    shbjdSubmit(formName) {
      let shForm = this.shForm;
      console.log(shForm, "审核参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 拒绝
          if (shForm.reviewPassed == 2) {
            this.discountReviewRejected({
              discount_id: this.$route.query.id,
              reason_refusal: shForm.remark
            });
            return;
          }
          // 通过
          this.discountReviewPassed({
            discount_id: this.$route.query.id,
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/shPage.scss";
</style>